package com.hsu.hiring.company.dao;

import java.util.List;

import com.hsu.hiring.common.util.DBUtil;
import com.hsu.hiring.common.util.Util;
import com.hsu.hiring.company.entity.PositionEntity;

/**
 * Position Dao
 *
 * @author Hsu.
 * @since 2016年1月14日
 */
public class PositionDao {

	/**
	 * 查询所有的职位
	 * 
	 * @return
	 */
	public List<PositionEntity> list() {
		String sql = "SELECT c.name as 'company$name', c.address as 'company$address', c.slogan as 'company$slogan', p.id, p.name, p.salary1, p.salary2, p.release_time FROM company c, position p WHERE c.id=p.company_id ORDER BY p.id DESC";
		List<PositionEntity> positionList = DBUtil.executeQuery(
				PositionEntity.class, sql);
		return positionList;
	}

	/**
	 * 根据职位id查询所对应详细信息
	 * 
	 * @param id
	 * @return
	 */
	public PositionEntity get(int id) {
		StringBuilder sb = new StringBuilder();
		sb.append("SELECT ");
		sb.append("c.name as 'company$name', ");
		sb.append("c.email as 'company$email', ");
		sb.append("c.phone as 'company$phone', ");
		sb.append("c.linkman as 'company$linkman', ");
		sb.append("c.address as 'company$address', ");
		sb.append("c.numbers as 'company$numbers', ");
		sb.append("c.slogan as 'company$slogan', ");
		sb.append("p.id, ");
		sb.append("p.name, ");
		sb.append("p.duty, ");
		sb.append("p.ability, ");
		sb.append("p.salary1, ");
		sb.append("p.salary2, ");
		sb.append("p.release_time ");
		sb.append("FROM company c, position p ");
		sb.append("WHERE c.id=p.company_id AND p.id=? ");
		return DBUtil.getUniqueResult(PositionEntity.class, sb.toString(), id);
	}

	public static void main(String[] args) {
		Util.printObject(new PositionDao().get(1));
	}

}
